﻿@model bugtracker.Models.ChangePasswordModel

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("ChangePassword","Account",FormMethod.Post, new { id = "changePWForm" }))
{
    @Html.ValidationSummary(true, "Password change was unsuccessful. Please correct the errors and try again.")
    <div>
        <fieldset>

            <p>
                New passwords are required to be a minimum of @Membership.MinRequiredPasswordLength characters in length.
            </p>

            <div class="editor-label">
                @Html.LabelFor(m => m.OldPassword)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.OldPassword)
                @Html.ValidationMessageFor(m => m.OldPassword)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.NewPassword)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.NewPassword)
                @Html.ValidationMessageFor(m => m.NewPassword)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.ConfirmPassword)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.ConfirmPassword)
                @Html.ValidationMessageFor(m => m.ConfirmPassword)
            </div>

            <p>
                <input type="submit" value="Change Password" />
                
            </p>
        </fieldset>
    </div>
}

<script type="text/javascript">
    /* attach a submit handler to the form */
    $(document).ready(function () {
        try {
            $("#changePWForm").submit(
				function (event) {
				    /* stop form from submitting normally */
				    event.preventDefault();

				    /* get some values from elements on the page: */
				    var $form = $(this),
					oldPw = $form.find('#OldPassword').val(),
					newPw = $form.find('#NewPassword').val(),
					conPw = $form.find('#ConfirmPassword').val(),
					url = $form.attr('action');

				    /* Send the data using post and put the results in a div */
				    $.post(url, { OldPassWord: oldPw, NewPassword: newPw, ConfirmPassword: conPw },
						function (data) {
						    var content = $(data);
						    $("#pwChange").empty().append(content);
						}
					);
				}
			);
        } catch (e) { alert(e); } 
    });
</script>
